<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>数组sort方法</title>
  </head>
  <body>
    <button onclick="sortArr()">排序</button>
    <script>
      const arr = [1, 2, 3, 16, 4, 5, 12, , 17, 6, 7, 8, 9, 10];
      const people = [
        {
          id: 1,
          name: "鸣人",
          age: 13,
        },
        {
          id: 2,
          name: "卡卡西",
          age: 32,
        },
        {
          id: 3,
          name: "懒羊羊",
          age: 23,
        },
        {
          id: 4,
          name: "小新",
          age: 5,
        },
      ];
      function sortArr() {
        // console.log(arr.sort((a, b) => Math.random() - 0.5));
        console.log(people.sort((a, b) => b.age - a.age));
      }
    </script>
  </body>
</html>
